package org.apache.harmony.javax.security.auth;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Principal;
import java.util.Iterator;
import java.util.Set;

public final class PrivateCredentialPermission extends Permission
{
  private static final long serialVersionUID = 5284372143517237068L;
  private static final String READ = "read";
  private String credentialClass;
  private transient int offset;
  private transient CredOwner[] set;

  public PrivateCredentialPermission(String paramString1, String paramString2)
  {
    super(paramString1);
    if ("read".equalsIgnoreCase(paramString2))
      initTargetName(paramString1);
    else
      throw new IllegalArgumentException("auth.11");
  }

  PrivateCredentialPermission(String paramString, Set<Principal> paramSet)
  {
    super(paramString);
    this.credentialClass = paramString;
    this.set = new CredOwner[paramSet.size()];
    Iterator localIterator = paramSet.iterator();
    while (localIterator.hasNext())
    {
      Principal localPrincipal = (Principal)localIterator.next();
      CredOwner localCredOwner = new CredOwner(localPrincipal.getClass().getName(), localPrincipal.getName());
      int i = 0;
      for (int j = 0; j < this.offset; j++)
        if (this.set[j].equals(localCredOwner))
        {
          i = 1;
          break;
        }
      if (i == 0)
        this.set[(this.offset++)] = localCredOwner;
    }
  }

  private void initTargetName(String paramString)
  {
    if (paramString == null)
      throw new NullPointerException("auth.0E");
    paramString = paramString.trim();
    if (paramString.length() == 0)
      throw new IllegalArgumentException("auth.0F");
    int i = paramString.indexOf(' ');
    if (i == -1)
      throw new IllegalArgumentException("auth.10");
    this.credentialClass = paramString.substring(0, i);
    i++;
    int j = 0;
    int k = paramString.length();
    int n = 0;
    while (i < k)
    {
      int m = paramString.indexOf(' ', i);
      n = paramString.indexOf('"', m + 2);
      if ((m == -1) || (n == -1) || (paramString.charAt(m + 1) != '"'))
        throw new IllegalArgumentException("auth.10");
      i = n + 2;
      j++;
    }
    if (j < 1)
      throw new IllegalArgumentException("auth.10");
    i = paramString.indexOf(' ');
    i++;
    this.set = new CredOwner[j];
    for (int i1 = 0; i1 < j; i1++)
    {
      int i2 = paramString.indexOf(' ', i);
      int i3 = paramString.indexOf('"', i2 + 2);
      String str1 = paramString.substring(i, i2);
      String str2 = paramString.substring(i2 + 2, i3);
      CredOwner localCredOwner = new CredOwner(str1, str2);
      int i4 = 0;
      for (int i5 = 0; i5 < this.offset; i5++)
        if (this.set[i5].equals(localCredOwner))
        {
          i4 = 1;
          break;
        }
      if (i4 == 0)
        this.set[(this.offset++)] = localCredOwner;
      i = i3 + 2;
    }
  }

  private void readObject(ObjectInputStream paramObjectInputStream)
    throws IOException, ClassNotFoundException
  {
    paramObjectInputStream.defaultReadObject();
    initTargetName(getName());
  }

  public String[][] getPrincipals()
  {
    String[][] arrayOfString = new String[this.offset][2];
    for (int i = 0; i < arrayOfString.length; i++)
    {
      arrayOfString[i][0] = this.set[i].principalClass;
      arrayOfString[i][1] = this.set[i].principalName;
    }
    return arrayOfString;
  }

  public String getActions()
  {
    return "read";
  }

  public String getCredentialClass()
  {
    return this.credentialClass;
  }

  public int hashCode()
  {
    int i = 0;
    for (int j = 0; j < this.offset; j++)
      i += this.set[j].hashCode();
    return getCredentialClass().hashCode() + i;
  }

  public boolean equals(Object paramObject)
  {
    if (paramObject == this)
      return true;
    if ((paramObject == null) || (getClass() != paramObject.getClass()))
      return false;
    PrivateCredentialPermission localPrivateCredentialPermission = (PrivateCredentialPermission)paramObject;
    return (this.credentialClass.equals(localPrivateCredentialPermission.credentialClass)) && (this.offset == localPrivateCredentialPermission.offset) && (sameMembers(this.set, localPrivateCredentialPermission.set, this.offset));
  }

  public boolean implies(Permission paramPermission)
  {
    if ((paramPermission == null) || (getClass() != paramPermission.getClass()))
      return false;
    PrivateCredentialPermission localPrivateCredentialPermission = (PrivateCredentialPermission)paramPermission;
    if ((!"*".equals(this.credentialClass)) && (!this.credentialClass.equals(localPrivateCredentialPermission.getCredentialClass())))
      return false;
    if (localPrivateCredentialPermission.offset == 0)
      return true;
    CredOwner[] arrayOfCredOwner1 = this.set;
    CredOwner[] arrayOfCredOwner2 = localPrivateCredentialPermission.set;
    int i = this.offset;
    int j = localPrivateCredentialPermission.offset;
    for (int k = 0; k < i; k++)
    {
      for (int m = 0; m < j; m++)
        if (arrayOfCredOwner1[k].implies(arrayOfCredOwner2[m]))
          break;
      if (m == arrayOfCredOwner2.length)
        return false;
    }
    return true;
  }

  public PermissionCollection newPermissionCollection()
  {
    return null;
  }

  private boolean sameMembers(Object[] paramArrayOfObject1, Object[] paramArrayOfObject2, int paramInt)
  {
    if ((paramArrayOfObject1 == null) && (paramArrayOfObject2 == null))
      return true;
    if ((paramArrayOfObject1 == null) || (paramArrayOfObject2 == null))
      return false;
    for (int j = 0; j < paramInt; j++)
    {
      int i = 0;
      for (int k = 0; k < paramInt; k++)
        if (paramArrayOfObject1[j].equals(paramArrayOfObject2[k]))
        {
          i = 1;
          break;
        }
      if (i == 0)
        return false;
    }
    return true;
  }

  private static final class CredOwner
    implements Serializable
  {
    private static final long serialVersionUID = -5607449830436408266L;
    String principalClass;
    String principalName;
    private transient boolean isClassWildcard;
    private transient boolean isPNameWildcard;

    CredOwner(String paramString1, String paramString2)
    {
      if ("*".equals(paramString1))
        this.isClassWildcard = true;
      if ("*".equals(paramString2))
        this.isPNameWildcard = true;
      if ((this.isClassWildcard) && (!this.isPNameWildcard))
        throw new IllegalArgumentException("auth.12");
      this.principalClass = paramString1;
      this.principalName = paramString2;
    }

    boolean implies(Object paramObject)
    {
      if (paramObject == this)
        return true;
      CredOwner localCredOwner = (CredOwner)paramObject;
      return ((this.isClassWildcard) || (this.principalClass.equals(localCredOwner.principalClass))) && ((this.isPNameWildcard) || (this.principalName.equals(localCredOwner.principalName)));
    }

    public boolean equals(Object paramObject)
    {
      if (paramObject == this)
        return true;
      if ((paramObject instanceof CredOwner))
      {
        CredOwner localCredOwner = (CredOwner)paramObject;
        return (this.principalClass.equals(localCredOwner.principalClass)) && (this.principalName.equals(localCredOwner.principalName));
      }
      return false;
    }

    public int hashCode()
    {
      return this.principalClass.hashCode() + this.principalName.hashCode();
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.apache.harmony.javax.security.auth.PrivateCredentialPermission
 * JD-Core Version:    0.6.1
 */